package www.study.com;

import java.util.*;

//字母异位词分组 https://leetcode.cn/problems/group-anagrams/
public class code49 {
    class Solution {
        public List<List<String>> groupAnagrams(String[] strs) {
            Map<String,List<String>> map = new HashMap<>();
            for(String s : strs) {
                char[] chs = s.toCharArray();
                Arrays.sort(chs);
                String sortedS = String.valueOf(chs);
                if(!map.containsKey(sortedS)){
                    map.put(sortedS,new ArrayList<>());
                }
                map.get(sortedS).add(s);
            }
            List<List<String>> res = new ArrayList<>();
            for(Map.Entry<String,List<String>> entry : map.entrySet()) {
                res.add(entry.getValue());
            }
            return res;
        }
    }
}
